Date.prototype.formatDate = function (dateFormat)    // eslint-disable-line no-extend-native
{
    let year = this.getFullYear();
    let month = this.getMonth() + 1;
    if (month > 0 && month < 10) 
    {
        month = '0' + month;
    }
    let day = this.getDate();
    if (day > 0 && day < 10) 
    {
        day = '0' + day;
    }
    let hour = this.getHours();
    let min = this.getMinutes();
    let seconds=this.getSeconds();
    if (dateFormat === 'YYYY-MM-DD') 
    {
        return `${year}-${month}-${day}`;
    }
    else if (dateFormat === 'MM-DD') 
    {
        return `${month}-${day}`;
    }
    else if (dateFormat === 'YYYY-MM') 
    {
        return `${year}-${month}`;
    }
    else if (dateFormat === 'YYYYMMDD') 
    {
        return `${year}${month}${day}`;
    } 
    else if (dateFormat === 'HH:mm') 
    {
        return `${hour}:${min}`;
    } 
    else if (dateFormat === 'YYYY年MM月DD日') 
    {
        return `${year}年${month}月${day}日`;
    }
    else if (dateFormat === 'YYYY-MM-DD HH:mm:ss') 
    {
        return `${year}-${month}-${day} ${hour}:${min}:${seconds}`;
    }
    else if (dateFormat === 'YYYY-MM-DD HH:mm') 
    {
        return `${year}-${month}-${day} ${hour}:${min}`;
    }
};

Date.prototype.addDays = function (offset)       // eslint-disable-line no-extend-native
{
    return new Date(this.getTime() + offset * 24 * 60 * 60 * 1000);
};

Date.prototype.diffDays = function (date)       // eslint-disable-line no-extend-native
{
    let time1 = Date.parse(this);
    let time2 = Date.parse(date);
    return (Math.abs(time2 - time1))/1000/60/60/24; 
};

Date.prototype.isAfter = function (date)       // eslint-disable-line no-extend-native
{
    let time1 = this.getTime();
    let time2 = date.getTime();
    return (time1 > time2);
};

export default class DateUtil
{
    static formatDate(date, dateFormat)
    {
        return new Date().formatDate(dateFormat);
    }
}
